package com.magic.uschat.util;

import java.io.File;

import com.magic.uschat.UsChatApplication;

import android.content.Context;
import android.content.res.Resources;
import android.os.Environment;

public class Util {
	
	 private static Context mContext = UsChatApplication.instance();
	
	public static boolean checkSdCard() {
        if (android.os.Environment.getExternalStorageState().equals(
                android.os.Environment.MEDIA_MOUNTED))
            return true;
        else
            return false;
    }
	
	/**
     * dpת px.
     *
     * @param value the value
     * @return the int
     */
    public static int dp2px(float value) {
        final float scale = mContext.getResources().getDisplayMetrics().densityDpi;
        return (int) (value * (scale / 160) + 0.5f);
    }
    /**
     * spת px.
     *
     * @param value the value
     * @return the int
     */
	public static int sp2px(float value){
		 Resources r;
	        if (mContext == null) {
	            r = Resources.getSystem();
	        } else {
	            r = mContext.getResources();
	        }
	        float spvalue = value * r.getDisplayMetrics().scaledDensity;
	        return (int) (spvalue + 0.5f);
	}
	
	public static File saveShortVideo(Context context){
		File root;
		if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
			root = Environment.getExternalStorageDirectory();
		}else{
			 root = context.getFilesDir();
		}
		File path = new File(root.getAbsolutePath()+"/uscaht"+"/shortvideo");
		if (!path.exists()) {
			path.mkdirs();
		}
		File file = new File(path,System.currentTimeMillis()+".mp4");
		return file;
	}
}
